package com.sh1604.duitang.fragment;


import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.sh1604.duitang.R;
import com.sh1604.duitang.adapter.MyPagerAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;


/**
 * A simple {@link Fragment} subclass.
 */
public class MyFragment extends Fragment {

    private MyPagerAdapter myPagerAdapter;
    private List<HashMap<String, Object>> listHP;


    @InjectView(R.id.tb_home)
    Toolbar tbHome;
    @InjectView(R.id.my_mainlv)
    ListView myMainlv;

    public MyFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_my, container, false);
        ButterKnife.inject(this, view);
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        Data();
        myPagerAdapter = new MyPagerAdapter(getContext(), listHP);
        myMainlv.setAdapter(myPagerAdapter);

        tbHome.inflateMenu(R.menu.my_menu);
        tbHome.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getContext(), "sb", Toast.LENGTH_SHORT).show();
            }
        });
    }

    private void Data() {
        listHP = new ArrayList<HashMap<String, Object>>();
        HashMap<String, Object> map1 = new HashMap<String, Object>();
        map1.put("id", R.mipmap.me_icon_luckybag);
        map1.put("title", "我的福袋");
        listHP.add(map1);
        HashMap<String, Object> map2 = new HashMap<String, Object>();
        map2.put("id", R.mipmap.icon_me_album);
        map2.put("title", "我的的专辑");
        listHP.add(map2);
        HashMap<String, Object> map3 = new HashMap<String, Object>();
        map3.put("id", R.mipmap.icon_explore_article);
        map3.put("title", "我的文章");
        listHP.add(map3);
        HashMap<String, Object> map4 = new HashMap<String, Object>();
        map4.put("id", R.mipmap.me_icon_collect);
        map4.put("title", "我的收藏");
        listHP.add(map4);
        HashMap<String, Object> map5 = new HashMap<String, Object>();
        map5.put("id", R.mipmap.me_icon_subscribe);
        map5.put("title", "我的订阅");
        listHP.add(map5);
        HashMap<String, Object> map6 = new HashMap<String, Object>();
        map6.put("id", R.mipmap.icon_me_comments);
        map6.put("title", "评论");
        listHP.add(map6);
        HashMap<String, Object> map7 = new HashMap<String, Object>();
        map7.put("id", R.mipmap.icon_me_notification);
        map7.put("title", "收藏/赞");
        listHP.add(map7);
        HashMap<String, Object> map8 = new HashMap<String, Object>();
        map8.put("id", R.mipmap.icon_me_message);
        map8.put("title", "聊天");
        listHP.add(map8);
        HashMap<String, Object> map9 = new HashMap<String, Object>();
        map9.put("id", R.mipmap.icon_follow);
        map9.put("title", "添加好友");
        listHP.add(map9);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.reset(this);
    }

}
